package org.geektimes.projects.user.sql;

import java.sql.*;

public class DerbyConnectionManager {

    private final static String URL = "jdbc:derby:/db/user-platform;create=true";

    private static Connection connection = null;


    private DerbyConnectionManager(){

    }


    public static Connection getConnection() {
        try{

            if (connection != null){
                return connection;
            }
            connection = DriverManager.getConnection(URL);
        }catch (Exception e){
            throw new RuntimeException(e.getCause());
        }

        return connection;
    }


    public static void close() {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                throw new RuntimeException(e.getCause());
            }
        }
    }

}
